package com.itqf.dao.impl;

import com.itqf.dao.AdminDao;
import com.itqf.entity.Admin;
import com.itqf.utils.DbUtils;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

import java.sql.SQLException;

public class AdminDaoImpl  implements AdminDao {

    //初始化Apache工具类
    private static QueryRunner queryRunner = new QueryRunner();

    @Override
    public Admin selectByUsername(String username) throws SQLException {

        //编写sql语句
        String sql = "select username,password from admin where username=?";

        //调用工具类的方法进行查询
        Admin query = queryRunner.query(DbUtils.getConnection(), sql, new BeanHandler<Admin>(Admin.class), username);
        return query;
    }
}
